package com.cssw.fyzb.tps.third.tf56pay.util;

import com.cssw.fyzb.tps.third.tf56pay.common.CharsetEnum;
import com.cssw.fyzb.tps.third.tf56pay.common.JsonResult;
import com.cssw.fyzb.tps.third.tf56pay.common.SignAlgorithmEnum;
import com.cssw.fyzb.tps.third.tf56pay.domain.dto.CertDTO;
import com.cssw.fyzb.tps.third.tf56pay.domain.vo.RsaDTO;
import com.cssw.fyzb.tps.third.tf56pay.sign.ItrusRSA;
import com.cssw.fyzb.tps.third.tf56pay.sign.MD5;
import com.cssw.fyzb.tps.third.tf56pay.sign.StandardRSA;

import java.util.Map;

public class SignUtils {

    public static JsonResult itrusRSASign(Map<String, Object> params, CertDTO certDTO) {
        return ItrusRSA.sign(params, certDTO);
    }

    public static JsonResult itrusRSASign(String plaintext, CertDTO certDTO) {
        return ItrusRSA.sign(plaintext, certDTO);
    }

    public static JsonResult itrusRSAVerify(Map<String, Object> params, CertDTO certDTO) {
        String sign = (String) params.get("tf_sign");
        return ItrusRSA.verify(params, sign);
    }

    public static JsonResult rsaSignWithSHA256(RsaDTO rsaDTO) {
        return StandardRSA.sign(rsaDTO.getPlaintext(), rsaDTO.getPrivateKey(), SignAlgorithmEnum.SHA256_RSA, CharsetEnum.UTF_8);
    }

    public static JsonResult rsaSignWithSHA1(RsaDTO rsaDTO) {
        return StandardRSA.sign(rsaDTO.getPlaintext(), rsaDTO.getPrivateKey(), SignAlgorithmEnum.SHA1_RSA, CharsetEnum.UTF_8);
    }

    public static JsonResult md5Sign(Map<String, String> oriParams, String sk) {
        return MD5.sign(oriParams,sk);
    }

    public static JsonResult md5Verify(Map<String, String> oriParams, String sk) {
        return MD5.verify(oriParams,sk);
    }



}
